{extend name="v1/layout/base"}
{block name="content"}
<div class="layuimini-main">

  <fieldset class="table-search-fieldset xk-search-status" id="xk-search-status">
    <legend>搜索信息</legend>
    <div style="margin: 10px 10px 10px 10px">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md6 xz_width">
          <form class="layui-form">
            <div class="layui-card-body layui-form layui-form-pane">
              <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg12">
                  <label class="layui-form-label">搜索关键词</label>
                  <div class="layui-input-block">
                    <input type="text" name="keywords" placeholder="会员号/订单编号（惠工宝）/开户人/身份证号" id="keywords" class="layui-input">
                  </div>
                </div>
              </div>
              <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg12">
                  <label class="layui-form-label">审核状态</label>
                  <div class="layui-input-block">
                    <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="0" title="等待审核">
                    <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="1" title="平台确认">
                    <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="2" title="平台驳回">
                    <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="3" title="三方打款成功">
                    <input type="checkbox" class="layui-input" lay-skin="primary" name="status" value="4" title="三方打款失败">
                  </div>
                </div>
              </div>
              <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg12">
                  <label class="layui-form-label">创建时间</label>
                  <div class="layui-input-block">
                    <input type="text" class="layui-input" autocomplete="off" id="search_time" placeholder="请选择对应的创建时间范围">
                  </div>
                </div>
              </div>
              <div class="layui-row">
                <div class="layui-col-xs4">&nbsp;</div>
                <div class="layui-col-xs4">
                  <button type="reset" class="layui-btn layui-btn-primary  xk-refresh"><i class="fa fa-refresh"></i>&nbsp;重置</button>
                  <button type="button" class="layui-btn layui-btn-normal xk-dosearch">搜索<i class="layui-icon"></i></button>
                  <button type="button" class="layui-btn layui-btn-primary close-search"><i class="layui-icon">&#x1007;</i>关闭</button>
                </div>
                <div class="layui-col-xs4">&nbsp;</div>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </fieldset>

  <script type="text/html" id="toolbar">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
      <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="doAgentFinance"><i class="layui-icon">&#xe67d;</i>一键审核</button>
      <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export"><i class="layui-icon">&#xe67d;</i>导出筛选后的数据</button>
      <div class="money_all"></div>
    </div>
  </script>

  <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
  <script type="text/html" id="currentTableBar">
    {{# if(d.status == 0){ }}
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" lay-event="doAgentFinance">处理</button>
   </div>
   {{# } }}
  </script>
  <script type="text/html" id="checkTemplate">
    {{# if(d.status == 0){ }}
    <input type="checkbox" name="with_drawal_id" id="{{d.with_drawal_id}}" class="layui-input layui-form-checkbox" value="{{d.with_drawal_id}}" lay-skin="primary" lay-filter="ldEvent"><i class="layui-icon"></i>
    {{# } }}
  </script>
</div>
{/block}
{block name="myScript"}
<script>
  layui.use(['form', 'table', 'laydate'], function() {
    var $ = layui.jquery,
      form = layui.form,
      table = layui.table;
    var laydate = layui.laydate;
    laydate.render({
      elem: '#search_time',
      range: '~',
      theme: '#1E9FFF',
      type: 'datetime',
    });
    table.render({
      elem: '#currentTableId',
      url: '/{:config("manage.manage_name")}/{:config("manage.version")}/Finance/withDrawalCheck',
      toolbar: '#toolbar',
      defaultToolbar: ['filter', {
        title: '搜索',
        layEvent: 'search',
        icon: 'layui-icon-search'
      }],
      height: 'full-50',
      cols: [
        [{
            templet: "#checkTemplate"
          },{
            field: 'user_name',
            width: '150',
            title: '会员昵称'
          },
          {
            field: 'user_sn',
            width: '100',
            title: '会员编号'
          },
          {
            field: 'order_sn',
            width: '200',
            title: '订单编号'
          },
          {
            field: 'money',
            width: '100',
            title: '申请金额'
          },
          {
            field: 'card_num',
            width: '200',
            title: '身份证号码'
          },
          {
            field: 'name',
            width: '100',
            title: '开户人'
          },
          {
            field: 'bank_name',
            width: '150',
            title: '开户行'
          },
          {
            field: 'bank_num',
            width: '200',
            title: '银行卡'
          },
          {
            field: 'status_txt',
            width: '150',
            title: '审核状态'
          },
          {
            field: 'create_time',
            width: '200',
            title: '创建时间'
          },
          {
            field: 'check_time',
            width: '15%',
            title: '平台审核时间'
          },
          {
            title: '操作',
            toolbar: '#currentTableBar',
            minWidth: '100',
            fixed: 'right',
            align: "center"
          }
        ]
      ],
      done: function (res, curr, count) {
        $(".money_all").html(res.resultData.show_count);
      },
      limits: [100, 150, 200, 250, 500, 1000],
      limit: 100,
      id: 'table_ids',
      page: true,
      skin: 'line'
    });
    // 顶部操作工具
    table.on('toolbar(currentTableFilter)', function(obj) {
      switch (obj.event) {
        case 'reseve':
          table.reload('table_ids');
          break;
        case 'doAgentFinance':
        var keywords = $("#keywords").val(),
          search_time = $("#search_time").val(),
          status = '',
          status_arr = [];
          url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Finance/withDrawalCheckSave";
          $("input[name=status]:checked").each(function() {
            status_arr.push($(this).val());
          });
          status = status_arr.join(',');
          choose_arr = getCheckValue();
          if(!choose_arr){
            layer.msg("请选择需要处理的提现记录");
            return false;
          }
          //确定要删除吗？
          layer.msg('请选择对于选中提现记录的处理！', {
            time: 0, //不自动关闭
            btn: ['线上审核通过', '拒绝','线下审核通过','取消'],
            yes: function(index) {
              layer.close(index);
              https(url, {
                act: 'all',
                id_str: choose_arr,
                status: 1
              }, 'post', true, '正在提交三方打款').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
                console.log(res);
              },error=>{

              })
            },
            btn2: function(index) {
              layer.close(index);
              https(url, {
                act: 'all',
                id_str: choose_arr,
                status: 2
              }, 'post', true, '正在执行审核拒绝').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
                console.log(res);
              },error=>{

              })
            },
            btn3: function(index) {
              layer.close(index);
              https(url, {
                act: 'all',
                id_str: choose_arr,
                status: 3
              }, 'post', true, '正在执行提现申请审核通过').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
                console.log(res);
              },error=>{

              })
            },
            btn4: function(index){
              layer.close(index);
            }
          });
          break;
        case 'export':
          var keywords = $("#keywords").val(),
            search_time = $("#search_time").val(),
            status = '',
            status_arr = [];
            url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Finance/exportWithDrawal";
            $("input[name=status]:checked").each(function() {
              status_arr.push($(this).val());
            });
            status = status_arr.join(',');
          https(url, {
            keywords: keywords,
            status: status,
            search_time: search_time
          }, 'post', true, '正在执行体现记录导出').then(res => {
            if (res.result_code == 200) {
              var html = '<h1 style="padding: 0 20px;color:red;font-size:18px;margin-bottom:15px;">如果数据量大于1万条系统自动分表导出</h1>';
              res.resultData.forEach(function(value, index) {
                html += '<h2 style="padding: 0 20px;font-size:16px;">第' + (index + 1) + '个订单文件：<a href="' + value + '">' + '下载' + '</a></h2>';
              })
              layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['400px', '200px'], //宽高
                content: html
              });
            }
          })
          break;
        case 'search':
          $("#xk-search-status").removeClass('xk-search-status');
          break;
      }
    })
    // 列表工具栏目
    table.on('tool(currentTableFilter)', function(obj) {
      var data = obj.data,
        event = obj.event;
      switch (event) {
        case 'doAgentFinance':
        var keywords = $("#keywords").val(),
          search_time = $("#search_time").val(),
          status = '',
          status_arr = [],
          finance_time = $("#finance_time").val();
          url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Finance/withDrawalCheckSave";
          $("input[name=status]:checked").each(function() {
            status_arr.push($(this).val());
          });
          status = status_arr.join(',');
          //确定要删除吗？
          layer.msg('请选择对会员'+data.user_name+'的金额为'+data.money+'元的提现申请的操作', {
            time: 0, //不自动关闭
            btn: ['审核通过', '拒绝', '线下审核通过', '取消'],
            yes: function(index) {
              layer.close(index);
              https(url, {
                id_str: data.with_drawal_id,
                status: 1
              }, 'post', true, '正在提交三方打款').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
              },error=>{

              })
            },
            btn2: function(index) {
              layer.close(index);
              https(url, {
                id_str: data.with_drawal_id,
                status: 2
              }, 'post', true, '正在执行驳回').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
              },error=>{

              })
            },
            btn3: function(index) {
              layer.close(index);
              https(url, {
                id_str: data.with_drawal_id,
                status: 3
              }, 'post', true, '正在执行提现申请审核通过').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
              },error=>{

              })
            },
            btn4: function(index){
              layer.close(index);
            }
          });
          break;
        case 'backAgentFinance':
        var keywords = $("#keywords").val(),
          search_time = $("#search_time").val(),
          status = '',
          status_arr = [],
          finance_time = $("#finance_time").val();
          url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Finance/withDrawalCheckSave";
          $("input[name=status]:checked").each(function() {
            status_arr.push($(this).val());
          });
          status = status_arr.join(',');
          //确定要删除吗？
          layer.msg('您是否确认将会员'+data.user_name+'的金额为'+data.money+'元的提现申请进行驳回？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function(index) {
              layer.close(index);
              https(url, {
                id_str: data.with_drawal_id,
                status: 2
              }, 'post', true, '正在提交驳回处理').then(res => {
                if (res.result_code == 200) {
                  table.reload('table_ids', {
                    where: {
                      keywords: keywords,
                      status: status,
                      search_time: search_time
                    }
                  });
                }
              },error=>{

              })
            },
            btn2: function(index) {
              layer.close(index);
            }
          });
          break;
        default:

      }

    })
    // 执行搜索
    $(".xk-dosearch").click(function() {
      var keywords = $("#keywords").val(),
        status = '',
        status_arr = [],
        search_time = $("#search_time").val();
        $("input[name=status]:checked").each(function() {
          status_arr.push($(this).val());
        });
        status = status_arr.join(',');
      table.reload('table_ids', {
        page: {
          curr: 1
        },
        where: {
          keywords: keywords,
          search_time: search_time,
          status: status
        }
      }, 'data');
    })
    // 获取选中项
    function getCheckValue(){
      var id_arr = [],
          id_str = '';
          $('input[name="with_drawal_id"]:checked').each(function(){
            id_arr.push($(this).val());
          });
          id_str = id_arr.join(',');
          return id_str;
    }
    // function getCheckValue() {
    //   var id_arr = [],
    //     id_str = '';
    //   var checkStatus = table.checkStatus('table_ids'),
    //     data = checkStatus.data;
    //   data.map(function(d) {
    //     id_arr.push(d.with_drawal_id);
    //   })
    //   id_str = id_arr.join(',');
    //   return id_str;
    // }
  });
</script>
{/block}
